package com.gejia.qixishare.rocketmq.consumer;

import com.gejia.qixishare.rocketmq.producer.QixiShareMessageProducer;
import com.gejia.qixishare.service.UploadRecordService;
import lombok.SneakyThrows;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@RocketMQMessageListener(topic = "${rocketmq.topic}", selectorExpression = "${rocketmq.statisticTag}", consumerGroup = "${rocketmq.producer.group}", consumeMode = ConsumeMode.ORDERLY)
public class QixiShareStatisticsConsumer  implements RocketMQListener<MessageExt> {
    @Autowired
    private UploadRecordService uploadRecordService;

    @Autowired
    private QixiShareMessageProducer qixiShareMessageProducer;

    @SneakyThrows
    @Override
    public void onMessage(MessageExt message) {
        String content = new String(message.getBody());
        System.err.println("QixiShareStatisticsConsumer onMessage:" + content);
        int num = uploadRecordService.count();
        qixiShareMessageProducer.sendQixiShareStatisticDataByOrder(String.valueOf(num));
    }
}
